package com.wcl.demo.application;

import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;

import com.baidu.mapapi.SDKInitializer;
import com.easemob.EMConnectionListener;
import com.easemob.EMError;
import com.easemob.chat.EMChat;
import com.easemob.chat.EMChatManager;
import com.easemob.chat.EMChatOptions;
import com.easemob.chat.EMConversation;
import com.easemob.chat.EMMessage;
import com.easemob.util.NetUtils;
import com.parse.Parse;
import com.wcl.demo.ui.activity.ChatActivity;
import com.wcl.demo.ui.activity.MainActivity;
import com.wcl.demo.utils.ParseManager;

/**
 * Created by dllo on 15/11/17.
 */
public class BaseApplication extends Application {
    private static Context mContext;


    public BaseApplication() {
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = getApplicationContext();
        //百度地图初始化
        SDKInitializer.initialize(this);
        EMChat.getInstance().setAutoLogin(true);
        //初始化SDK
        EMChat.getInstance().init(getContext());
        /**
         * debugMode == true 时为打开，sdk 会在log里输入调试信息
         * @param debugMode
         * 在做代码混淆的时候需要设置成false
         */
        EMChat.getInstance().setDebugMode(true);
        EMChatManager.getInstance().getChatOptions().setUseRoster(true);
        // 获取到EMChatOptions对象
        EMChatOptions options = EMChatManager.getInstance().getChatOptions();
        // 默认添加好友时，是不需要验证的，改成需要验证
        options.setAcceptInvitationAlways(false);
        // 默认环信是不维护好友关系列表的，如果app依赖环信的好友关系，把这个属性设置为true
        options.setUseRoster(true);
        EMChat.getInstance().setAppInited();
        Parse.initialize(getContext(), "UUL8TxlHwKj7ZXEUr2brF3ydOxirCXdIj9LscvJs", "B1jH9bmxuYyTcpoFfpeVslhmLYsytWTxqYqKQhBJ");
    }

    public static Context getContext() {
        return mContext;
    }


    @Override
    public Context getApplicationContext() {
        return super.getApplicationContext();
    }

    /***
     * 此方法主要为了在苹果推送时能够推送昵称(nickname)而不是userid,
     * 一般可以在登陆成功后从自己服务器获取到个人信息，然后拿到nickname更新到环信服务器
     *
     * @param nickname
     */
    public BaseApplication(String nickname) {
        //此方法传入一个字符串String类型的参数，返回成功或失败的一个Boolean类型的返回值
        EMChatManager.getInstance().updateCurrentUserNick(nickname);
    }
}
